package cn.wolfcode.web.controller;

import cn.wolfcode.common.exception.BusinessException;
import cn.wolfcode.common.web.CommonCodeMsg;
import cn.wolfcode.common.web.Result;
import cn.wolfcode.domain.SeckillProduct;
import cn.wolfcode.domain.SeckillProductVo;
import cn.wolfcode.service.ISeckillProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/seckillProduct")
@Slf4j
public class SeckillProductController {
    @Autowired
    private ISeckillProductService seckillProductService;
    
    @RequestMapping("/querySeckillProduct")
    public Result querySeckillProduct(){
        return Result.success(seckillProductService.querySeckillProduct());
    }
    
    @GetMapping("/queryByTime")
    public Result queryByTime(@RequestParam("time") Integer time){
        if (StringUtils.isEmpty(time)){
            throw new BusinessException(CommonCodeMsg.NO_SECKILL_PRODUCT);
        }
        return Result.success(seckillProductService.querySeckillProductByTime(time));
    }
    
    @GetMapping("/find")
    public Result find(@RequestParam("time") Integer time,@RequestParam("seckillId") Integer seckillId){
        if (StringUtils.isEmpty(time)||StringUtils.isEmpty(seckillId)){
            throw new BusinessException(CommonCodeMsg.NO_PRODUCT_ID);
        }
        return Result.success(seckillProductService.find(time,seckillId));
    }
}
